﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
/// <summary>
/// MyPage 的摘要说明
/// </summary>
public class MyPage : System.Web.UI.Page
{
	public MyPage()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}

    //调整分页代码
    public void Pager(Literal RecordCount, Literal PageCount, Literal Pageindex, Literal pageSelect,
        HyperLink FirstPage, HyperLink PrevPage, HyperLink NextPage, HyperLink LastPage,
        int count, int pageCount, int curPage, string str)
    { 
        RecordCount.Text = count.ToString();
        PageCount.Text = pageCount.ToString();
        Pageindex.Text = curPage.ToString();
        pageSelect.Text = PageList(pageCount, curPage, str);
        
        FirstPage.NavigateUrl = Request.CurrentExecutionFilePath + "?page=1" + str;
        PrevPage.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + (curPage - 1) + str;
        NextPage.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + (curPage + 1) + str;
        LastPage.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + pageCount + str;

        if (curPage <= 1 && pageCount <= 1)
        {
            FirstPage.NavigateUrl = "";
            PrevPage.NavigateUrl = "";
            NextPage.NavigateUrl = "";
            LastPage.NavigateUrl = "";
        }
        if (curPage <= 1 && pageCount > 1)
        {
            FirstPage.NavigateUrl = "";
            PrevPage.NavigateUrl = "";
        }
        if (curPage >= pageCount)
        {
            NextPage.NavigateUrl = "";
            LastPage.NavigateUrl = "";
        }
    }
    //生成页面跳转select
    public string PageList(int pageCount, int pageIndex, string str)
    {
        StringBuilder sb = new StringBuilder();
        sb.Append("<select id=\"Page_Jump\" name=\"Page_Jump\" onchange=\"window.location='" + Request.CurrentExecutionFilePath
            + "?page='+this.options[this.selectedIndex].value+'" + str + "'\">");

        for (int i = 1; i <= pageCount; i++)
        {
            if (pageIndex == i)
            {
                sb.Append("<option value='" + i + "' selected>" + i + "</option>");
            }
            else
            {
                sb.Append("<option value='" + i + "' >" + i + "</option>");
            }
        }

        sb.Append("</select>");

        return sb.ToString();
    }
}
